import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import leout from '../leout'

import settingsRouter from './modules/settings'
import social_securitysRouter from './modules/social_securitys'
import permissionsRouter from './modules/permissions'
import approvalsRouter from './modules/approvals'
import departmentsRouter from './modules/departments'
import salarysRouter from './modules/salarys'
import employeesRouter from './modules/employees'
import attendancesRouter from './modules/attendances'

export const asyncRoutes = [
  settingsRouter,
  social_securitysRouter,
  permissionsRouter,
  approvalsRouter,
  departmentsRouter,
  salarysRouter,
  employeesRouter,
  attendancesRouter
]

export const constantRoutes = [
  
  // 登陆
  {
    path: '/login',
    name: 'Login',
    hidden: false, 
    component: () => import('../views/Login.vue'),
  },
  //以下为测试页面
  {
    path: '/about', 
    name: 'About',
    hidden: false, 
    component: () => import(/* webpackChunkName: "About" */ '../views/About.vue')
  },
    {
    path: "/", //vue3基本语法演示
    component: leout,
      redirect: "/index",
    hidden:true,
    children: [
      {
        path: "/index",
        name: "index",
        component: () => import("../views/index/index.vue"),
        meta: { title: "首页", icon: "index" },
      },
    ],
  },
  {
    path: '/test',//vue3基本语法演示
    name: 'Test',
     hidden: false, 
    component: () => import(/* webpackChunkName: "Test" */ '../views/Test.vue')
  },
   //根目录,到登录页面
   {
     path: '/',
     hidden: false, 
     redirect: '/login'
  },
  //找不到页面到404,！！注意vue3里不能用*
  // {
  //  path: '/:catchAll(.*)',
  //  redirect: '/404'
  // }
]

const router = createRouter({
  history: createWebHashHistory(), // hash模式：createWebHashHistory，history模式：createWebHistory
  routes:[...constantRoutes]
})

let menus = JSON.parse(localStorage.getItem('menus'))||[]
const newRoutes = [] // 存储当前用户所拥有的权限路由
   menus.forEach(key => {
   // key标识
   // 洒
   newRoutes.push(...asyncRoutes.filter(item => item.name === key)) 
})
newRoutes.forEach(item => {
    console.log(30,item);
    router.addRoute(item)
})



export default router
